<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="com.biz.conf.Global"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jqGird</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <style>
        .ml10 {
            margin-left: 15px;
        }
        .wddd-list-jtzl {
            padding: 10px 0 0 !important;
            text-align: center;
        }.wddd-list-jtzl>ul>li {
             float: left;
             cursor: pointer;
         }
    ul,li{
        list-style-type: none;
    }

    </style>

</head>

<body class="gray-bg" >
<div class="wrapper wrapper-content  animated fadeInRight" id="ccbb">
    <div class="row">
        <div class="col-sm-12">
            <div class="toolbar">
                <div id="toolbar">
                  <%--  <button onclick="order_excel_deshopMain();" class="btn btn-primary"><i class="fa fa-file-excel-o"></i>&nbsp;导出订单</button>
                    <button onclick="showPopup();" class="btn btn-primary"><i class="fa fa-file-excel-o"></i>&nbsp;导出订单明细</button>--%>
                </div>
            </div>
            <span id="spancc" class="spancc"></span>
            <div class="row">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>搜索条件</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content" >
                        <div class="row">
                            <div class="col-md-2"><input placeholder="订单号" id="search_code" class="form-control" ></div>
                            <div class="col-md-2"><input placeholder="开始日期" id="search_startdate" class="form-control layer-date" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" ></div>
                            <div class="col-md-2"><input placeholder="结束日期" id="search_enddate" class="form-control layer-date" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" ></div>
                            <div class="col-md-1"><button id="btn_search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;搜索</button></div>
                        </div>
                    </div>
                    <div class="ibox-content" >
                        <div class="row">
                            <div class="col-md-4"><i id="zdddze" class="glyphicon glyphicon-usd">合计：(现金<span id="cashTotal">0.00</span>,久零贝<span id="coinTotal">0.00</span>)</i></div>
                            <div class="col-md-4"><i id="zdfqze" class="glyphicon glyphicon-yen">退款：(现金<span id="cashBack">0.00</span>,久零贝<span id="coinBack">0.00</span>) </i></div>
                            <div class="col-md-2"><i id="zdfyze" class="glyphicon glyphicon-credit-card">订单笔数：<span id="orderCount">0</span></i></div>
                            <div class="col-md-2"><i id="zdddbs" class="glyphicon glyphicon-list-alt">退款笔数：<span id="backCount">0</span></i></div>
                        </div>
                    </div>
                </div>
            </div>
            <table id="exampleTablePagination"></table>
        </div>
    </div>
</div>

<script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/bootstrap-table.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/locale/bootstrap-table-zh-CN.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/export/bootstrap-table-export.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/editable/bootstrap-table-editable.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/layer/laydate/laydate.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/layer2.4/layer.js"></script>

<script>

</script>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script type="text/javascript">
    //初始化表格对象
    var $table = $('#exampleTablePagination');

    /*
     获取选中行的相关数据
     */
    $(function () {
        $table.on('click-row.bs.table', function (e, row, $element) {
            $('.success').removeClass('success');
            $($element).addClass('success');
        });
        $('#button').click(function () {
            alert('Selected name: ' + getSelectedRow().userName);
        });

        //加载统计信息
        loadSumInfo();
    });
    function getSelectedRow() {
        var index = $table.find('tr.success').data('index');
        return $table.bootstrapTable('getData')[index];
    }

    /*
     每一列详情格式化数据
     */
    function formDetail(index, row) {
        return row.detail+index;
    }


    function showPopup(id,detailId){
        //自定页
        layer.open({
            type: 2,
            shift:2,//动画类型
            moveType:1,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            title:'<span style="font-weight:600;font-size: 13px;color:#676a6c;">订单详情</span>',
            area: ['700px', '530px'],
            content: '${pageContext.request.contextPath}/order/toDetail.ac?id='
            + id+'&detailId='+detailId,
            success: function(layero, index){
                var datas={"firstname":"555555"};
                var body = layer.getChildFrame('body', index);
                //var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                console.log(body.html()); //得到iframe页的body内容
            },
            cancel: function(index){
//                alert(index);
                return true;
            }
        });
    }



    function showDeliverPop(mainid, message){
        //自定页
        layer.open({
            type: 2,
            shift:2,//动画类型
            moveType:1,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            title:'<span style="font-weight:600;font-size: 13px;color:#676a6c;">发货单</span>',
            area: ['400px', '480px'],
            content: '${pageContext.request.contextPath}/order/orderSendList.ac?orderid='
                        + mainid+'&message='+window.encodeURI(window.encodeURI(message)),
            success: function(layero, index){
//                var datas={"firstname":"555555"};
//                var body = layer.getChildFrame('body', index);
//                //var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
//                console.log(body.html()); //得到iframe页的body内容
            },
            cancel: function(index){
//                alert(index);
                return true;
            }
        });
    }


    ////////////////////////////////////////////////////////////////////////////////////////以下是通过js方式初始化BootStrapTable/////////////////////////////////////////////

    $table.bootstrapTable({
        url: "${pageContext.request.contextPath}/order/showOrderUnions.ac",
        method: 'post',
        contentType: "application/x-www-form-urlencoded",//必须的
        dataType: "json",
        pageList:[10, 20, 50, 100],//会根据当前的数据量加载合适的pageList
        height: ($(window).height()-100) ,
        //cardView:true,//是否自适应手机
        pagination: true, //分页
        // queryParamsType: "limit",
        singleSelect: false,
        cache:false,
        sortName:"createTime",
        search: false, //显示搜索框
        showColumns:false,
        showRefresh:false,
        showToggle:false,
        showPaginationSwitch:false,
        smartDisplay:true,
        detailView:true,
        toolbar:"#toolbar",
        queryParams: queryParams,//参数
        searchOnEnterKey:true,
        detailFormatter:function(index, record, element){
            var html='</br>';
            html+='<div class=\"wddd-list-jtzl\">'+
                    '<ul style="margin-top:10px;"  >'+
                    '<li style=\"width:20%\">购买人:</li>'+
                    '<li style=\"width:20%\">'+record.buyerName+'</li>'+
                    '<li style=\"width:20%\">买家留言:</li>'+
                    '<li style=\"width:40%;word-wrap:break-word;\"> <div style="width:400px;word-wrap:break-word;">'+record.buyNotes+'</div></li>'+
                    '</ul>'+
                    '<br class="clear"/>'+
                    '<ul style="margin-top:10px;">'+
                    '<li style=\"width:20%;line-height:20px;\">商品信息:'+record.goodsName+'</li>';
            if(record.mainType == '3'){
                html+='<li style=\"width:20%;line-height:20px;\"><img src="<%=Global.getConfig("OSSURL_mainType3")%>/';
            }else{
                html+='<li style=\"width:20%;line-height:20px;\"><img src="<%=Global.getConfig("OSSURL")%>/';
            }
            html+= record.goodsPath
                    + '" width="100" height="100"></li>'
                    + '<li style=\"width:20%;line-height:20px;\">售价:'
                    + record.goodPrice
                    + '</li>'
                    + '<li style=\"width:40%;line-height:20px;\">数量:'
                    + record.count
                    + '</li>'
                    + '</ul>';
            '<br class="clear"/>'+
            + '<ul style="margin-top:10px;">'
            + '<li style=\"width:20% \"></li>'
            + '<li style=\"width:40% \"></li>'
            + '<li style=\"width:20%\"></li>'
            + '<li style=\"width:20%\"></li>' + '</ul>';
            '<br class="clear"/>';
            return html;
        },
        sidePagination: "server", //服务端处理分页
        columns: [

            {field:'mainId', title:'编号', type:'string', align: 'center',visible:false},
            {field:'code', title:'订单编号', type:'string', align: 'center'},
            {field:'paycode',title:'支付单号', type:'string', align: 'center'},
            {field:'goodsName', title:'商品名称', type:'string', align: 'center',formatter:function(value){
                if(value.length>10)
                {
                    return value.substring(0,9)+"...";
                }else{
                    return value;
                }
            }},
            {field:'isGroup', title:'来源', type:'string', align: 'center',formatter:function(value){
                if(value==3)
                {
                    return '<span style="color:green">体验店</span>';
                }else{
                    return '<span style="color:blue">商城</span>';
                }
            }},
            {field:'createTime', title:'下单时间', type:'string', align: 'center'},
            {field:'alltotal', title:'合计总额', type:'string', align: 'center'},
            {field:'payTotal', title:'实付金额', type:'string', align: 'center',formatter:function(value){
                return value+'元';
            }},
            {field:'couponsPayTotal', title:'久零券', type:'string', align: 'center',formatter:function(value){
                if(value != undefined)
                {
                    return value+'券';
                }else{
                    return '0券';
                }
            }},
            {field:'coinPayTotal',title:'久零币金额', type:'string', align: 'center',formatter:function(value){
                if(value != undefined)
                {
                    return value;
                }else{
                    return '0';
                }
            }},    {field:'detailState', title:'订单状态', type:'string',align: 'center',formatter:function(value, record, column, grid, dataNo,
                                                                                                        columnNo){
                if (value==0){
                    return "<font color='red'>待付款</font>";
                } else if(value==1)  {
                    return "<font color='green'>待核券</font>";
                }else if(value==2){
                    return "待收货";
                }else if(value==3){
                    return "待评价";
                }else if(value==4){
                    return "完成";
                }else if(value==5){
                    return "退款中";
                }else if(value==6){
                    return "已退款";
                }else if(value==7){
                    return "待备货";
                }else{
                    return "备货前退款";
                }
            }},
            {field:'mainState',title:'付款状态', type:'string',align: 'center',formatter:function(value){
                if (value==0){
                    return "<font color='red'>未付款</font>";
                } else if(value==1)  {
                    return "<font color='green'>已付款</font>";
                }
            }},
            {field:'isClosed', title:'关闭状态', type:'string',align: 'center',formatter:function(value,record){
                if (value==0){
                    return "<font color='green'>正常</font>";
                } else if(value==1)  {
                    return "<font color='red'>已关闭</font>";
                }
            }},{
                title: '操作',
                align: 'center',
                formatter:function(value,row,index){
                    if(row.isClosed == 0&&(row.detailState==1||row.detailState==2||row.detailState==3))
                    {
                        return [
                            '<a class="search" onclick="showPopup(\''+row.mainId+'\',\''+row.detailId+'\');" href="javascript:void(0)" title="详情">',
                            '<i class="glyphicon glyphicon-search"></i>',
                            '</a>&nbsp;&nbsp;&nbsp;&nbsp;',
                            '<a class="barcode" onclick="scanOrder(\''+row.mainId+'\',\''+row.detailId+'\');" href="javascript:void(0)" title="扫码消券">',
                            '<i class="glyphicon glyphicon-barcode"></i>',
                            '</a>&nbsp;&nbsp;&nbsp;&nbsp;',
                            '<a class="remove" onclick="closeOrder(\''+row.mainId+'\');" href="javascript:void(0)" title="关闭">',
                            '<i class="glyphicon glyphicon-remove"></i>',
                            '</a>',
                        ].join('');
                    }else if(row.isClosed == 0){
                        return [
                            '<a class="search" onclick="showPopup(\''+row.mainId+'\',\''+row.detailId+'\');" href="javascript:void(0)" title="详情">',
                            '<i class="glyphicon glyphicon-search"></i>',
                            '</a>&nbsp;&nbsp;&nbsp;&nbsp;',
                            '<a class="remove" onclick="closeOrder(\''+row.mainId+'\');" href="javascript:void(0)" title="关闭">',
                            '<i class="glyphicon glyphicon-remove"></i>',
                            '</a>',
                        ].join('');
                    }else{
                        return [
                            '&nbsp;&nbsp;&nbsp;&nbsp;<a class="search" onclick="showPopup(\''+row.mainId+'\',\''+row.detailId+'\');" href="javascript:void(0)" title="详情">',
                            '<i class="glyphicon glyphicon-search"></i>',
                            '</a>&nbsp;&nbsp;&nbsp;&nbsp;',
                        ].join('');
                    }
                }
            }
        ]
    });

    /*
     搜索按钮
     */
    $("#btn_search").click(function(){
        $table.bootstrapTable('selectPage', 1);
        $table.bootstrapTable('refresh', queryParams);
    });

    /*
     传递的参数
     */
    function queryParams(params) {
        var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            limit: params.limit,  //页面大小
            offset: params.offset, //页码
            pageindex:params.pageNumber,
            code: $("#search_code").val(),
            startDate: $("#search_startdate").val(),
            endDate: $("#search_enddate").val()
        };
        return temp;
    }
    ///////////////////////////////////////////////////////////////toolbar///////////////////////////////////////
    //新增
    $("#btn_add").click(function(){
        showPopup();
    });

    //批量删除
    $("#btn_del").click(function(){
        var ids=getSelections();
        //执行批量删除
        deleteGrid(ids);
    });

    /*
     批量删除方法体
     */
    function closeOrder(mainId){
            swal({
                title: "您确定要关闭此订单吗？",
                text: "关闭后将无法恢复，请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "关闭",
                cancelButtonText:"取消",
                closeOnConfirm: false
            }, function () {
                //执行批量删除
                $.ajax( {
                    url:'${pageContext.request.contextPath}/order/closeOrder.ac',
                    data:{
                        id :mainId
                    },
                    type:'post',
                    cache:false,
                    dataType:'json',
                    success:function(data) {
                        if(data.state == '1'){
                            swal("关闭成功！", "您已经关闭了这个订单。", "success");
                            //当前表格刷新
                            $table.bootstrapTable('refresh');
                        }else{
                            swal("删除失败！", "未能关闭此订单。", "error");
                        }
                    },
                    error : function() {
                        alert("异常！");
                    }
                });

            });
    }

    // 打开订单详情
    function openDetail(id,detailId) {
        window.location.href = "${pageContext.request.contextPath}/order/toDetail.ac?id="
                + id+"&detailId="+detailId;
    }

    //获取选中的CheckBox
    $("#btn_getCheck").click(function(){
        alert('getSelections: ' + JSON.stringify($table.bootstrapTable('getSelections')));
        alert("客户信息:"+$table.bootstrapTable('getSelections')[0].userName);
    });

    function order_excel_deshopMain() {

        var params = {};
        params['startDate'] = $("#search_startdate").val();
        params['endDate'] = $("#search_enddate").val();
        params['code'] = $("#search_code").val();
        params['shopId'] = "1283163cd39a4d729a86026c8e601d0c";

        var str = encodeURI(encodeURI(JSON.stringify(params)));
        window.location.href = "${pageContext.request.contextPath}/order/exportExcel_shopDeMain.ac?parameters="
                + str;
    }

    function order_excel_deshop() {
        var params = {};
        var params = {};
        params['startdate'] = $("#search_startdate").val();
        params['enddate'] = $("#search_enddate").val();
        params['code'] = $("#search_code").val();
        params['shopId'] = "1283163cd39a4d729a86026c8e601d0c";

        var str = encodeURI(encodeURI(JSON.stringify(params)));

        window.location.href = "${pageContext.request.contextPath}/order/exportExcel_shopDeDetail.ac?parameters="
                + str;
    }



    <%--function DeliverGoods(mainid, message) {--%>
        <%--$("#form_type").val("0");--%>
        <%--$(':input', '#form').val('');--%>
        <%--$("#doc-modal-1").modal('open');--%>
        <%--$("#form_id").val(mainid);//选中的orderid--%>

        <%--$("#select_sandType").val(1);//默认自己配送--%>
        <%--selectUrlType();--%>
        <%--$--%>
                <%--.ajax({--%>
                    <%--url : '${pageContext.request.contextPath}/order/orderSendList.action?orderid='--%>
                    <%--+ mainid,--%>
                    <%--type : 'post',--%>
                    <%--success : function(data) {--%>
                        <%--var jsondate = JSON.parse(data);--%>
                        <%--$("#select_recPersonName").html(--%>
                                <%--jsondate[0].recPersonName);//收件人姓名--%>
                        <%--$("#select_userphone").html(jsondate[0].userphone);//收件人电话--%>
                        <%--$("#select_buyAddr").html(jsondate[0].buyAddr);//地址--%>
                        <%--$("#select_message").html(message);//留言--%>

                    <%--}--%>
                <%--});--%>

    <%--}--%>


    function reloadTable(){
        $table.bootstrapTable('refresh');
    }
function scanOrder(orderId,detailId)
{
    //自定页
    parent.layer.open({
        type: 2,
        shift:4,//动画类型
        moveType:1,
        maxmin: true,
        shadeClose: true, //开启遮罩关闭
        area: ['800px', '600px'],
        content: '${pageContext.request.contextPath}/orderStatistics/orther_toCheckVoucherForBrand.ac?orderId='+orderId,
        success: function(layero, index){
        },
        cancel: function(index){
            $table.bootstrapTable('refresh', queryParams);
            return true;
        },
        close  : function(index){

            $table.bootstrapTable('refresh', queryParams);
        }
    });

}
        //加载统计信息
        function loadSumInfo()
        {

            var params = {};
            var startD = $("#search_startdate").val();
            var endD= $("#search_enddate").val();
            var paramCode = $("#search_code").val();


            $.ajax({
                url:'${pageContext.request.contextPath}/order/loadUnionSumInfo.ac',
                type:'post',
                data:{startDate:startD,endDate:endD,code :paramCode},
                dataType:'json',
                success:function(data)
                {
                    $("#cashTotal").html(parseFloat(data.cashTotal).toFixed(2));
                    $("#coinTotal").html(parseFloat(data.coinTotal).toFixed(2));
                    $("#cashBack").html(parseFloat(data.cashBack).toFixed(2));
                    $("#coinBack").html(parseFloat(data.coinBack).toFixed(2));
                    $("#orderCount").html(data.orderCount);
                    $("#backCount").html(data.backCount);
                }
            });
        }

</script>
</body>


</html>
